package colopllet.colopl.pc.session;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;

import colopllet.colopl.pc.session.ColoplSession;

public class ColoplSessionImpl implements ColoplSession {
    
    private static final long serialVersionUID = -3771047320782995227L;
    
    private String username;
    private String password;
    private String cookieUsername;
    private String id;
    private String uid;
    private String jsessionid;
    private String pt;
    private int accessCount;
    
    private Map<String, Object> attributes = new HashMap<String, Object>();
//    private Semaphore semaphore = new Semaphore(1);
    
    
    public ColoplSessionImpl(String username,
            String password,
            String id,
            String uid,
            String jsessionid,
            String pt) {
        
        this.username = username;
        this.password = password;
        this.id = id;
        this.uid = uid;
        this.jsessionid = jsessionid;
        this.pt = pt;
    }
    
//    public void acquire() throws InterruptedException {
//        semaphore.acquire();
//    }
//    
//    public void release() {
//        semaphore.release();
//    }
    
    public boolean isLoggedIn() {
        if (id == null || uid == null || jsessionid == null) {
            return false;
        }
        return true;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getJsessionid() {
        return jsessionid;
    }

    public void setJsessionid(String jsessionid) {
        this.jsessionid = jsessionid;
    }

    public String getPt() {
        return pt;
    }

    public void setPt(String pt) {
        this.pt = pt;
    }
    
    public void setAttribute(String key, Object value) {
        this.attributes.put(key, value);
    }
    
    public Object getAttribute(String key) {
        return this.attributes.get(key);
    }


    public int getAccessCount() {
        return this.accessCount;
    }

    public void setAccessCount(int count) {
        this.accessCount = count;
    }

    public String toString() {
        return "User [username=" + username + ", password=" + password
                + ", id=" + id + ", uid=" + uid + ", jsessionid=" + jsessionid
                + ", pt=" + pt + "]";
    }

    public String getCookieUsername() {
        return this.cookieUsername;
    }

    public void setCookieUsername(String username) {
        this.cookieUsername = username;
    }
    

}
